package com.nats.sample.quickstart._01;

import com.nats.sample.common.util.NatsConnUtil;
import io.nats.client.Connection;
import io.nats.client.Dispatcher;
import io.nats.client.Subscription;
import java.nio.charset.StandardCharsets;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class _01NatsSubTestMain {

  public static void main(String[] args) throws Exception {
    log.info("subscribe start");

    Connection nc = NatsConnUtil.getConn();

    Dispatcher d = nc.createDispatcher((msg) -> {});

    Subscription s = d.subscribe("hello", (msg) -> {
      String response = new String(msg.getData(), StandardCharsets.UTF_8);
      System.out.println("Message received: " + response);
    });

  }


}
